home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / hopes_babysitting_maze.swf / scripts / __Packages / Classes / bsmPlayer.as < prev   
Text File  |  2011-08-19  |  9KB  |  302 lines

  1. class Classes.bsmPlayer extends Classes.bsmEntity
  2. {
  3.    var INVINCIBLE_TIME = 3;
  4.    var SLOW_TIME_EASY = 3;
  5.    var SLOW_TIME_HARD = 5;
  6.    var speed = 90;
  7.    var SCENTERX = 287.5;
  8.    var SCENTERY = 200;
  9.    function bsmPlayer(t_data, t_levelPath)
  10.    {
  11.       super();
  12.       this.assetID = t_data.assetID;
  13.       this.x = t_data.x;
  14.       this.y = t_data.y;
  15.       this.pushedBy = null;
  16.       this.levelPath = t_levelPath;
  17.    }
  18.    function spawn(t_path, t_depth)
  19.    {
  20.       this.path = t_path;
  21.       this.mc = t_path.attachMovie(this.assetID,this.assetID + t_depth,t_depth);
  22.       this.mc.stop();
  23.       this.placeAt(this.x,this.y);
  24.       this.hdOffsetPoint = {x:0,y:0};
  25.       this.path.hd.localToGlobal(this.hdOffsetPoint);
  26.       this.pushedBy = null;
  27.       this.baseWidth = 25;
  28.       this.baseHeight = 30;
  29.       this.hdWidth = 20;
  30.       this.hdHeight = 20;
  31.       this.render();
  32.    }
  33.    function hit(t_enemy)
  34.    {
  35.       this.push(t_enemy);
  36.    }
  37.    function push(t_enemy)
  38.    {
  39.       var _loc4_ = this.calculateFacingHD(this,t_enemy.mc);
  40.       if(_loc4_.collision)
  41.       {
  42.          this.xMove = 0;
  43.          this.yMove = 0;
  44.       }
  45.       var _loc3_ = this.calculateFacingHD(t_enemy,this.mc);
  46.       if(_loc3_.collision)
  47.       {
  48.          if(t_enemy.type == "perfume")
  49.          {
  50.             if(t_enemy.ignoreTimer <= 0 && t_enemy.sprayTimer <= 3)
  51.             {
  52.                t_enemy.sprayPerfume();
  53.                t_enemy.turnAround();
  54.             }
  55.          }
  56.          this.pushedBy = t_enemy;
  57.          if(_loc3_.dir == "left")
  58.          {
  59.             this.xMove += t_enemy.xMove;
  60.          }
  61.          else if(_loc3_.dir == "right")
  62.          {
  63.             this.xMove += t_enemy.xMove;
  64.          }
  65.          else if(_loc3_.dir == "up")
  66.          {
  67.             this.yMove += t_enemy.yMove;
  68.          }
  69.          else if(_loc3_.dir == "down")
  70.          {
  71.             this.yMove += t_enemy.yMove;
  72.          }
  73.       }
  74.    }
  75.    function update(t_elapsed)
  76.    {
  77.       var _loc5_ = this.xMove;
  78.       var _loc6_ = this.yMove;
  79.       this.xMove = 0;
  80.       this.yMove = 0;
  81.       if(t_elapsed > 0.04)
  82.       {
  83.          t_elapsed = 0.04;
  84.       }
  85.       if(!this.hidden)
  86.       {
  87.          var _loc2_ = this.speed * t_elapsed;
  88.          if(this.slowTimer > 0)
  89.          {
  90.             _loc2_ /= 3;
  91.             this.slowTimer -= t_elapsed;
  92.             if(this.slowTimer <= 0)
  93.             {
  94.                this.mc.cloud.gotoAndStop("off");
  95.             }
  96.          }
  97.          if(Key.isDown(37))
  98.          {
  99.             this.xMove = - _loc2_;
  100.             this.mc.gotoAndStop("left");
  101.          }
  102.          else if(Key.isDown(38))
  103.          {
  104.             this.yMove = - _loc2_;
  105.             this.mc.gotoAndStop("up");
  106.          }
  107.          else if(Key.isDown(39))
  108.          {
  109.             this.xMove = _loc2_;
  110.             this.mc.gotoAndStop("right");
  111.          }
  112.          else if(Key.isDown(40))
  113.          {
  114.             this.yMove = _loc2_;
  115.             this.mc.gotoAndStop("down");
  116.          }
  117.          else if(_loc5_ != 0 || _loc6_ != 0)
  118.          {
  119.             var _loc3_ = "standUp";
  120.             if(_loc6_ > 0)
  121.             {
  122.                _loc3_ = "standDown";
  123.             }
  124.             else if(_loc5_ > 0)
  125.             {
  126.                _loc3_ = "standRight";
  127.             }
  128.             else if(_loc5_ < 0)
  129.             {
  130.                _loc3_ = "standLeft";
  131.             }
  132.             this.mc.gotoAndStop(_loc3_);
  133.          }
  134.          if(this.invincibleTimer > 0)
  135.          {
  136.             this.invincibleTimer -= t_elapsed;
  137.          }
  138.       }
  139.    }
  140.    function move()
  141.    {
  142.       if(this.xMove != 0 || this.yMove != 0)
  143.       {
  144.          var _loc3_ = this.calculateFacingHD(this,this.path.hd);
  145.          if(_loc3_.collision)
  146.          {
  147.             if(this.pushedBy != null)
  148.             {
  149.                this.pushedBy.turnAround();
  150.                this.pushedBy = null;
  151.             }
  152.             var _loc4_ = 0;
  153.             var _loc5_ = 0;
  154.             var _loc2_ = _loc3_.points.length;
  155.             while(true)
  156.             {
  157.                _loc2_;
  158.                if(!_loc2_--)
  159.                {
  160.                   break;
  161.                }
  162.                if(_loc3_.points[_loc2_].collide)
  163.                {
  164.                   if(_loc3_.points[_loc2_].point == "cr" || _loc3_.points[_loc2_].point == "cl" || _loc3_.points[_loc2_].point == "ct" || _loc3_.points[_loc2_].point == "cb")
  165.                   {
  166.                      _loc5_ = 0;
  167.                      _loc4_ = 0;
  168.                      _loc2_ = 0;
  169.                   }
  170.                   else if(_loc3_.points[_loc2_].point == "tl")
  171.                   {
  172.                      if(this.xMove < 0)
  173.                      {
  174.                         _loc4_ = Math.abs(this.xMove);
  175.                      }
  176.                      else if(this.yMove < 0)
  177.                      {
  178.                         _loc5_ = Math.abs(this.yMove);
  179.                      }
  180.                   }
  181.                   else if(_loc3_.points[_loc2_].point == "tr")
  182.                   {
  183.                      if(this.xMove > 0)
  184.                      {
  185.                         _loc4_ = this.xMove;
  186.                      }
  187.                      else if(this.yMove < 0)
  188.                      {
  189.                         _loc5_ = this.yMove;
  190.                      }
  191.                   }
  192.                   else if(_loc3_.points[_loc2_].point == "br")
  193.                   {
  194.                      if(this.xMove > 0)
  195.                      {
  196.                         _loc4_ = - this.xMove;
  197.                      }
  198.                      else if(this.yMove > 0)
  199.                      {
  200.                         _loc5_ = - this.yMove;
  201.                      }
  202.                   }
  203.                   else if(_loc3_.points[_loc2_].point == "bl")
  204.                   {
  205.                      if(this.xMove < 0)
  206.                      {
  207.                         _loc4_ = this.xMove;
  208.                      }
  209.                      else if(this.yMove > 0)
  210.                      {
  211.                         _loc5_ = this.yMove;
  212.                      }
  213.                   }
  214.                }
  215.             }
  216.             this.x += _loc5_;
  217.             this.y += _loc4_;
  218.          }
  219.          else
  220.          {
  221.             this.x += this.xMove;
  222.             this.y += this.yMove;
  223.          }
  224.       }
  225.    }
  226.    function hide()
  227.    {
  228.       this.slowTimer = 0;
  229.       this.mc.cloud.gotoAndStop("off");
  230.       super.hide();
  231.    }
  232.    function calculateFacingHD(t_entity, t_mc)
  233.    {
  234.       var _loc4_ = {tl:false,tr:false,bl:false,br:false,cb:false,cl:false,cr:false,ct:false};
  235.       var _loc11_ = undefined;
  236.       if(t_entity.xMove < 0)
  237.       {
  238.          _loc11_ = "left";
  239.          _loc4_.tl = true;
  240.          _loc4_.cl = true;
  241.          _loc4_.bl = true;
  242.       }
  243.       else if(t_entity.xMove > 0)
  244.       {
  245.          _loc11_ = "right";
  246.          _loc4_.tr = true;
  247.          _loc4_.cr = true;
  248.          _loc4_.br = true;
  249.       }
  250.       if(t_entity.yMove < 0)
  251.       {
  252.          _loc11_ = "up";
  253.          _loc4_.tl = true;
  254.          _loc4_.tr = true;
  255.          _loc4_.ct = true;
  256.       }
  257.       else if(t_entity.yMove > 0)
  258.       {
  259.          _loc11_ = "down";
  260.          _loc4_.bl = true;
  261.          _loc4_.br = true;
  262.          _loc4_.cb = true;
  263.       }
  264.       var _loc7_ = t_entity.x + t_entity.xMove;
  265.       var _loc6_ = t_entity.y + t_entity.yMove;
  266.       var _loc8_ = undefined;
  267.       var _loc10_ = undefined;
  268.       var _loc13_ = 2;
  269.       if(_loc11_ == "up" || _loc11_ == "down")
  270.       {
  271.          _loc8_ = t_entity.hdWidth / _loc13_;
  272.          _loc10_ = t_entity.hdHeight / _loc13_;
  273.       }
  274.       else
  275.       {
  276.          _loc8_ = t_entity.hdHeight / _loc13_;
  277.          _loc10_ = t_entity.hdWidth / _loc13_;
  278.       }
  279.       var _loc9_ = false;
  280.       var _loc3_ = [{point:"tl",x:_loc7_ - _loc8_,y:_loc6_ - _loc10_},{point:"tr",x:_loc7_ + _loc8_,y:_loc6_ - _loc10_},{point:"bl",x:_loc7_ - _loc8_,y:_loc6_ + _loc10_},{point:"br",x:_loc7_ + _loc8_,y:_loc6_ + _loc10_},{point:"cr",x:_loc7_ + _loc8_ + 2,y:_loc6_},{point:"cb",x:_loc7_,y:_loc6_ + _loc10_ + 2},{point:"cl",x:_loc7_ - _loc8_ - 2,y:_loc6_},{point:"ct",x:_loc7_,y:_loc6_ - _loc10_ - 2}];
  281.       var _loc2_ = _loc3_.length;
  282.       while(true)
  283.       {
  284.          _loc2_;
  285.          if(!_loc2_--)
  286.          {
  287.             break;
  288.          }
  289.          _loc3_[_loc2_].collide = false;
  290.          if(_loc4_[_loc3_[_loc2_].point])
  291.          {
  292.             _loc3_[_loc2_].collide = t_mc.hitTest(_loc3_[_loc2_].x + this.hdOffsetPoint.x,_loc3_[_loc2_].y + this.hdOffsetPoint.y,true);
  293.             if(_loc3_[_loc2_].collide)
  294.             {
  295.                _loc9_ = true;
  296.             }
  297.          }
  298.       }
  299.       return {collision:_loc9_,dir:_loc11_,points:_loc3_};
  300.    }
  301. }
  302.